package com.mfhcd.facepay.utils;

import android.text.TextUtils;
import android.widget.Toast;

import com.mfhcd.facepay.App;


/**
 * Toast工具类
 */

public class ToastUtil {

    private static Toast mToast;

    public static void showToast(int resId) {
        if (mToast == null) {
            mToast = Toast.makeText(App.getInstance(), resId, Toast.LENGTH_SHORT);
        } else {
            mToast.cancel();
            mToast = Toast.makeText(App.getInstance(), resId, Toast.LENGTH_SHORT);
        }
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.setText(resId);
        mToast.show();
    }

    public static void showToast(String text) {
        if (!TextUtils.isEmpty(text)) {
            if (mToast == null) {
                mToast = Toast.makeText(App.getInstance(), text, Toast.LENGTH_SHORT);
            } else {
                mToast.cancel();
                mToast = Toast.makeText(App.getInstance(), text, Toast.LENGTH_SHORT);
            }
            mToast.setDuration(Toast.LENGTH_SHORT);
            mToast.setText(text);
            mToast.show();
        }
    }

    public static void showLongToast(String text) {
        if (!TextUtils.isEmpty(text)) {
            if (mToast == null) {
                mToast = Toast.makeText(App.getInstance(), text, Toast.LENGTH_LONG);
            } else {
                mToast.cancel();
                mToast = Toast.makeText(App.getInstance(), text, Toast.LENGTH_LONG);
            }
            mToast.setDuration(Toast.LENGTH_LONG);
            mToast.setText(text);
            mToast.show();
        }
    }

    public static void dismiss() {
        if (mToast != null) {
            mToast.cancel();
            mToast = null;
        }
    }

}
